cmake_minimum_required(VERSION 2.8)

if(NOT DEFINED CMAKE_TOOLCHAIN_FILE)
	if(DEFINED ENV{VITASDK})
		set(CMAKE_TOOLCHAIN_FILE "$ENV{VITASDK}/share/vita.toolchain.cmake" CACHE PATH "toolchain file")
	else()
		message(FATAL_ERROR "Please define VITASDK to point to your SDK path!")
	endif()
endif()

project(SWD3E C CXX)
include("${VITASDK}/share/vita.cmake" REQUIRED)

#set(VITA_APP_NAME "轩辕剑叁外传天之痕")
set(VITA_APP_NAME "SWD3E")
set(VITA_TITLEID "SWD3E0000")
set(VITA_VERSION "01.03")
set(VITA_MKSFOEX_FLAGS "-d ATTRIBUTE2=12")

set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -Wl,-q,--wrap,memcpy,--wrap,memmove,--wrap,memset -Wall -O3 -mfloat-abi=softfp")
set(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS} -std=c++11")

add_definitions(-D__vita__ -DDEBUG -DNDEBUG_FILE -DNSHOW_RESOLVE_INFO)

include_directories(
	${CMAKE_SOURCE_DIR}/loader
	${CMAKE_SOURCE_DIR}/imports/include
	${CMAKE_SOURCE_DIR}/imports/include/SDL2
	${VITASDK}/arm-vita-eabi/include/SDL2
)

link_directories(
	${CMAKE_SOURCE_DIR}/imports/lib
)

add_executable(SWD3E.elf
	loader/main.c
	loader/dialog.c
	loader/so_util.c
	loader/jni.c
	loader/dynlib.c
	loader/utils.c
	loader/config.c
	loader/patch/patch.c
	loader/patch/swd3e_import.c
	loader/patch/font_cache.c
	loader/patch/avplayer.c
	loader/patch/patch_android.c
	loader/patch/patch_file.c
	loader/patch/patch_font.c
	loader/patch/patch_sdl.c
	loader/patch/patch_sdl_ss2d.c
	loader/patch/patch_commButtonClass.c
	loader/patch/patch_UIGamePad.c
	loader/patch/patch_binker.c
	loader/patch/patch_setting.c
)

target_link_libraries(SWD3E.elf
	-Wl,--whole-archive pthread -Wl,--no-whole-archive
	SDL2_mixer
	SDL2_ttf
	SDL2_image
	SDL2
	smpeg2
	freetype
	vorbisfile
	vorbis
	mikmod
	ogg
	webp
	mpg123
	FLAC
	jpeg
	png
	z
	m
	stdc++
	vitaGL
	vitashark
	mathneon
	kubridge_stub
	SceAppMgr_stub
	SceAudio_stub
	SceAudioIn_stub
	SceCtrl_stub
	SceCommonDialog_stub
	SceDisplay_stub
	SceKernelDmacMgr_stub
	SceGxm_stub
	SceShaccCg_stub
	SceSysmodule_stub
	ScePower_stub
	SceTouch_stub
	SceVshBridge_stub
	SceHid_stub
	SceMotion_stub
	SceAppUtil_stub
	SceAvPlayer_stub
)

vita_create_self(eboot.bin SWD3E.elf UNSAFE)
vita_create_vpk(SWD3E.vpk ${VITA_TITLEID} eboot.bin
	VERSION ${VITA_VERSION}
	NAME ${VITA_APP_NAME}
	FILE ${CMAKE_SOURCE_DIR}/sce_sys/icon0.png sce_sys/icon0.png
	${CMAKE_SOURCE_DIR}/sce_sys/pic0.png sce_sys/pic0.png
	${CMAKE_SOURCE_DIR}/sce_sys/livearea/contents/bg.png sce_sys/livearea/contents/bg.png
	${CMAKE_SOURCE_DIR}/sce_sys/livearea/contents/startup.png sce_sys/livearea/contents/startup.png
	${CMAKE_SOURCE_DIR}/sce_sys/livearea/contents/template.xml sce_sys/livearea/contents/template.xml
)
